home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / attachCurveLine.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.8 KB  |  103 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Jan 12, 1998
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The attachCurveLine() procedure takes the selected two curves and 
  26. //        creates a one span straight curve between them, using the end of curve1
  27. //      and the start of curve2. The result will always be at least a degree
  28. //      3 curve. If you don't want to attach the curves then call this proc
  29. //      with $doAttach = 0.
  30. //
  31. //  Input Arguments:
  32. //      $doAttach - if 1 attach results otherwise just create new curve
  33. //
  34. //  Return Value:
  35. //      String.
  36. //
  37.  
  38. global proc string attachCurveLine( int $doAttach )
  39. {
  40.     global int $gSelectNurbsCurvesBit;
  41.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`;
  42.  
  43.     int $numCurves = size($curvesList);
  44.     if ( $numCurves < 2 )
  45.     {
  46.         error("Need to select two curves.");
  47.         return "";
  48.     }
  49.  
  50.     // get the last cv on the first curve and the first cv on the second curve
  51.     //
  52.     int $degree = eval("getAttr " + $curvesList[0] + ".degree");
  53.     int $numSpans = eval("getAttr " + $curvesList[0] + ".spans");
  54.     int $numCVs = $degree + $numSpans;
  55.  
  56.     int $lastCV = $numCVs - 1;
  57.     float $cvCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`;
  58.     float $cvCurve2[] = `getAttr ($curvesList[1] + ".cp[0]")`;
  59.  
  60.     // this is the vector between the two cvs
  61.     //
  62.     float $vector[3];
  63.     $vector[0] = $cvCurve2[0] - $cvCurve1[0];
  64.     $vector[1] = $cvCurve2[1] - $cvCurve1[1];
  65.     $vector[2] = $cvCurve2[2] - $cvCurve1[2];
  66.  
  67.     // calculate two other cvs on the line between the end cvs
  68.     //
  69.     float $cvNew1[3];
  70.     $cvNew1[0] = $cvCurve1[0] + ($vector[0] * 0.333);
  71.     $cvNew1[1] = $cvCurve1[1] + ($vector[1] * 0.333);
  72.     $cvNew1[2] = $cvCurve1[2] + ($vector[2] * 0.333);
  73.     float $cvNew2[3];
  74.     $cvNew2[0] = $cvCurve1[0] + ($vector[0] * 0.666);
  75.     $cvNew2[1] = $cvCurve1[1] + ($vector[1] * 0.666);
  76.     $cvNew2[2] = $cvCurve1[2] + ($vector[2] * 0.666);
  77.  
  78.     // create the degree 3 curve
  79.     //
  80.     string $resultCurve = eval("curve -p " + $cvCurve1[0] + " " + $cvCurve1[1] + " " + $cvCurve1[2] + " -p " + $cvNew1[0] + " " + $cvNew1[1] + " " + $cvNew1[2] + " -p " + $cvNew2[0] + " " + $cvNew2[1] + " " + $cvNew2[2] + " -p " + $cvCurve2[0] + " " + $cvCurve2[1] + " " + $cvCurve2[2] + " -k 0 -k 0 -k 0 -k 1 -k 1 -k 1");
  81.  
  82.     // attach all 3 curves if required
  83.     //
  84.     if ( $doAttach == 1 )
  85.     {
  86.         // attach curve1 to the new curve
  87.         //
  88.         string $attachedCurve[] = eval("attachCurve -ch 0 -rpo 0 -kmk 1 " + $curvesList[0] + " " + $resultCurve);
  89.  
  90.         // the straight curve is no longer needed
  91.         //
  92.         delete $resultCurve;
  93.  
  94.         // attach curve2 to the previously attached curves
  95.         //
  96.         $attachedCurve = eval("attachCurve -ch 0 -rpo 1 -kmk 1 " + $attachedCurve[0] + " " + $curvesList[1]);
  97.         $resultCurve = $attachedCurve[0];
  98.     }
  99.  
  100.     select -r $resultCurve;
  101.     return $resultCurve;
  102. }
  103.